<?php
/**
 * @修改：莫深辰
 * @时间:    2018-05-03 10:35:26
 * @功能: 销货单 明细表
 */
header('Access-Control-Allow-Origin: *');
require( "config.php");

// insert
$op = $_POST['op'];
if($op == 'add'){

$data = $_POST;

$data['transType'] = '150601';
$data['transTypeName'] = '销货';
$data['billType'] = 'SALE';
$data['locationId'] = '1';
$data['billDate'] = date('Y-m-d');
$data['salesId'] =$_POST['salesId'];

//TODO 
//订单明细表
//收入表

unset($data['op']);

 // die(json_encode($data));

 $id = $db->insert('ci_invoice_info',$data);
 if($id){
	$re['status'] = '200';
	$re['msg'] = $id;
 }else{
	$re['status'] = '110';
	$re['msg'] = '添加失败！';
 }
 die(json_encode($re));
 }

// update
if($op == 'update'){

 $id =  $_POST['id'];
$data = $_POST;
unset($data['op']);

 $where = 'id = '.$id;
 $id = $db->update('ci_invoice_info',$data,$where);

 if($id){
	$re['status'] = '200';
	$re['msg'] =  $op.' success!';
 }else{
	$re['status'] = '110';
	$re['msg'] = $op.' failed!';;
 }
 	die(json_encode($re));
 }

//delete
 if($op == 'delete'){

 $id =  $_POST['id'];
 $where = 'id = '.$id;
 $id = $db->delete('ci_invoice_info',$where);

 if($id){
	$re['status'] = '200';
	$re['msg'] =  $op.' success!';
 }else{
	$re['status'] = '110';
	$re['msg'] = $op.' failed!';;
 }
 	die(json_encode($re));
 }

//find
 if($op == 'find'){

 $id =  $_POST['id'];
 $where = 'id = '.$id;
  $db->find('ci_invoice_info','*',$where);
  $re1 = $db->fetch_assoc();

 if($re1){
	$re['status'] = '200';
	$re['msg'] =  $re1;
 }else{
	$re['status'] = '110';
	$re['msg'] = $op.' failed!';;
 }
 	die(json_encode($re));
 }

//select
 if($op == 'select'){

 $where =  $_POST['where'];
 $re1 = $db->select('ci_invoice_info','*',$where);

 if($re1){
	$re['status'] = '200';
	$re['msg'] =  $re1;
 }else{
	$re['status'] = '110';
	$re['msg'] = $op.' failed!';;
 }
 	die(json_encode($re));
 }
 die('no op!');
